#include <iostream>
#include <vector>
using namespace std;
class Solution {
    const int INF = INT_MAX / 2;
public:
    int maxDistance(vector<vector<int>>& arrays) {
        int maximumDistance = 0;
        int minNum = INF, maxNum = -INF;
        for (vector<int> array : arrays) {
            int first = array.front(), last = array.back();
            int currDistance = max(maxNum - first, last - minNum);
            maximumDistance = max(maximumDistance, currDistance);
            minNum = min(minNum, first);
            maxNum = max(maxNum, last);
        }
        return maximumDistance;
    }
};
int main()
{
	return 0;
}